<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
Connection conn=null;
Statement stmt=null;
try{
	Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){
	System.out.print("la classe est introuvale");
	e.printStackTrace();
	}
try{
	String url="jdbc:mysql://localhost:3306/base_labrocante";
	String user="root";
	String pw="";
	String idAnnonce = request.getParameter("idannonce");
	conn=DriverManager.getConnection(url,user,pw);
	stmt = conn.createStatement();
	String req1="SELECT * FROM annonce WHERE idAnnonce='"+idAnnonce+"'";
	String req2="SELECT * FROM ville";
	String req3="SELECT * FROM categorie";
	PreparedStatement ps = conn.prepareStatement(req1);
	PreparedStatement ps1 = conn.prepareStatement(req2);
	PreparedStatement ps2 = conn.prepareStatement(req3);
	ResultSet rset = ps.executeQuery();
	ResultSet rset1 = ps1.executeQuery();
	ResultSet rset2 = ps2.executeQuery();
%>

<h2>Update Annonce Number: <%=idAnnonce%></h2>

<form action="updateAnnonce_2.jsp" method="post">
	<table>
	<%if (rset.next()){ %>
		<tr>
			<td>Titre:</td>
			<td><input type="text" name="titre" value="<%=rset.getString("titre")%>" ></td>
		</tr>
		<tr>
			<td>Annonce Description: </td>
			<td><textarea rows="5" cols="20" name="texteAnnonce"><%=rset.getString("texteAnnonce")%></textarea></td>
		</tr>
		<tr>
			<td>Telephone: </td>
			<td><input type="text" name="tel" value="<%=rset.getString("tel")%>"  ></td>
		</tr>
		<tr>
			<td>prix: </td>
			<td><input type="text" name="prix" value="<%=rset.getString("prix")%>"  ></td>
		</tr>
		<tr>
			<td>ville: </td>
			<td>
				<select name="ville">
					<%while(rset1.next()){ %>
					<option  value="<%=rset1.getString("nomVille")%>" ><%=rset1.getString("nomVille")%></option>
					<%}%>
				</select>
			</td>
		</tr>
		<tr>
			<td>Categorie: </td>
			<td>
				<select name="categorie">
					<%while(rset2.next()){ %>
					<option value="<%=rset2.getString("nomCat")%>"><%=rset2.getString("nomCat")%></option>
					<%}%>
				</select>
			</td>
		</tr>
	<%}%>
	</table>
	<input type="hidden" name="idannonce" value="<%=idAnnonce%>" />
	<input type="submit" name="update" value="update" >
</form>

<%
}
catch(SQLException e){
e.printStackTrace();
}
%>

</body>
</html>